#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

ll L, R;
int vis[N], primes[N], tot;
void init(int n) {
  vis[1] = 1;
  rep(i, 2, n) {
    if (!vis[i]) primes[++tot] = i;
    rep(j, 1, tot) {
      ll k = 1ll * primes[j] * i;
      if (k > n) break;
      vis[k] = 1;
      if (i % primes[j] == 0) break;
    }
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init(1e6);
  while (cin >> L >> R) {
    rep(i, 1, R + 1 - L) vis[i] = 0;
    rep(i, 1, tot) {
      ll p = primes[i];
      if (p * p > R) break;
      ll s = (L + p - 1) / p * p;
      for (ll j = max(s, p * p); j <= R; j += p) vis[j - L + 1] = 1;
    }
    vector<int> a;
    rep(i, 1, R + 1 - L) if (!vis[i] && i + L - 1 != 1) a.push_back(i + L - 1);
    if (a.size() <= 1)
      cout << "There are no adjacent primes." << endl;
    else {
      int mn = a[1] - a[0], mx = mn;
      pii x(a[0], a[1]), y(a[0], a[1]);
      for (int i = 2; i < a.size(); i++) {
        if (a[i] - a[i - 1] < mn) mn = a[i] - a[i - 1], x = pii(a[i - 1], a[i]);
        if (a[i] - a[i - 1] > mx) mx = a[i] - a[i - 1], y = pii(a[i - 1], a[i]);
      }
      cout << x.first << ',' << x.second << " are closest, ";
      cout << y.first << ',' << y.second << " are most distant." << endl;
    }
  }
  return 0;
}
